package cn.tedu.egmvc04.controller;

import ch.qos.logback.core.joran.util.beans.BeanUtil;
import cn.tedu.egmvc04.mapper.AddressMapper;
import cn.tedu.egmvc04.pojo.dto.AddressAddParam;
import cn.tedu.egmvc04.pojo.entity.Address;
import cn.tedu.egmvc04.pojo.vo.AddressInfoVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/v1/address/")
public class AddressController {
    @Autowired
    private AddressMapper addressMapper;
    @RequestMapping("add")
    public String addAdd(AddressAddParam param){
        System.out.println("addAdd");

        int num = addressMapper.insertAddress(param);
        if (num>0){
            return "添加成功";
        }else {
            return "添加失败";
        }
    }
    @RequestMapping("list")
    public List<AddressInfoVO> selectAll(){
        System.out.println("selectAll:查询成功");
        return addressMapper.selectAddress();
    }
    @RequestMapping("del")
    public String delAddres(Integer id){
        System.out.println("delAddres:删除成功");
        int num = addressMapper.deleteIdAdd(id);
        if (num>0){
            return "删除成功";
        }else {
        return "删除失败";
    }
    }
}
